#!/usr/bin/env python
################################################################################
#
#   plot_scaling
# 
#
#
#   Copyright (C) 2007 Leo Goodstadt
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; version 2
#   of the License
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#################################################################################
"""
    plot_scaling.py

"""

import sys, os
import os.path
import re
import StringIO
import glob
import shutil

# add self to search path for testing
if __name__ == '__main__':
    exe_path = os.path.split(os.path.abspath(sys.argv[0]))[0]
    sys.path.append(exe_path)

# get module name
if __name__ == '__main__':
    myname = os.path.splitext(os.path.split(sys.argv[0])[1])[0];
else:
    myname = __name__

class plot_scaling (object):
    def __init__ (self, x_scale, 
                        y_scale, 
                        x_pos = 0, 
                        y_pos = 0,
                        x_offset = 0,
                        y_offset = 0):
        self.x_scale  = float(x_scale )
        self.y_scale  = float(y_scale )
        self.x_pos    = float(x_pos   )
        self.y_pos    = float(y_pos   )
        self.x_offset = float(x_offset)
        self.y_offset = float(y_offset)
    def x_scaled (self, x):
            return (x * self.x_scale)
    def y_scaled (self, y):
            return (y * self.y_scale)
    def to_x (self, x):
        return (x - self.x_offset) * self.x_scale + self.x_pos
    def to_y (self, y):
        return (y - self.y_offset) * self.y_scale + self.y_pos
    def __str__ (self):
        return ("(p - offset) * scale + pos\n" + 
                "scale = [%g, %g]\n" + 
                "offset = [%g, %g]\n" +
                "pos = [%g, %g]\n") % (
                    self.x_scale  ,
                    self.y_scale  ,
                    self.x_pos    ,
                    self.y_pos    ,
                    self.x_offset ,
                    self.y_offset)
